//
//  ZParticipateCell.m
//  WeClubs
//
//  Created by Zed Link on 12/4/2017.
//  Copyright © 2017 Zed. All rights reserved.
//

#import "ZParticipateCell.h"
#import <UIImageView+WebCache.h>

@interface ZParticipateCell ()

@property (weak, nonatomic) IBOutlet UIImageView *logoImgView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *jobLabel;
@property (weak, nonatomic) IBOutlet UILabel *subjectLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
@property (weak, nonatomic) IBOutlet UIButton *checkInBtn;

@end

@implementation ZParticipateCell

- (void)zSetupCell
{
    [super zSetupCell];
    
    [self.logoImgView zCornerDeal:20];
    [self.confirmBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -5, 0, 0)];
    [self.checkInBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -5, 0, 0)];
    self.separatorInset = UIEdgeInsetsMake(0, 56, 0, 0);
}

- (void)updateParticipate
{
    self.nameLabel.text = self.participateModel.name;
    self.jobLabel.text = self.participateModel.jobName;
    self.subjectLabel.text = self.participateModel.departmentName;
    
    NSString *avatarURL = self.participateModel.avatarUrl;
    if (avatarURL != nil) { 
        [self.logoImgView sd_setImageWithURL:[NSURL URLWithString:avatarURL]];
    }
    
    NSArray *confirmIconNames = @[@"sign_ic_uncertain", @"sign_ic_leave", @"sign_ic_sure"];
    NSArray *confirmTitles = @[@"确认", @"请假", @"确认"];
    int index = self.participateModel.isConfirm;
    
    [self.confirmBtn setTitle:confirmTitles[index] forState:UIControlStateNormal];
    [self.confirmBtn setImage:[UIImage imageNamed:confirmIconNames[index]] forState:UIControlStateNormal];
    
    NSString *checkInImageName = self.participateModel.isSign == 0 ? @"sign_ic_uncertain" : @"sign_ic_sure";
    [self.checkInBtn setImage:[UIImage imageNamed:checkInImageName] forState:UIControlStateNormal];
    
    
    // Todo: 后台修改参数, 日期, 请假的理由
}

#pragma mark - Getter & Setter

- (void)setParticipateModel:(ZParticipateModel *)participateModel
{
    _participateModel = participateModel;
    [self updateParticipate];
}

@end
